﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Admin_Performance : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadGroup();
        }
    }

    private void LoadGroup()
    {
        ddlGroup.Items.Clear();
        DataTable dt = new DataTable();
        dt = DALTask.GetGroup();
        ddlGroup.Items.Add("--Select One--");
        ddlGroup.SelectedIndex = ddlGroup.Items.IndexOf(ddlGroup.Items.FindByText("--Select One--"));
        ListItem list = new ListItem();
        list.Text = "All";
        list.Value = "0";
        ddlGroup.Items.Add(list);
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            ListItem li = new ListItem();
            li.Text = dt.Rows[i][1].ToString();
            li.Value = dt.Rows[i][0].ToString();
            ddlGroup.Items.Add(li);
        }
    }

    private void bindGrid(int groupId)
    {
        DataTable dt = new DataTable();
        dt = AdminCreateTestDAL.GetStudentPerformanceRecord(groupId);
        gvStudent.DataSource = dt;
        gvStudent.DataBind();
    }

   
    protected void btnShow_Click(object sender, EventArgs e)
    {
        bindGrid(Convert.ToInt32(ddlGroup.SelectedItem.Value));
    }

    protected void ClearRecord_Click(object sender, EventArgs e)
    {
        gvStudent.DataSource = null;
        gvStudent.DataBind();
    }

    protected void gvStudent_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        object userId = e.CommandArgument;
        switch (e.CommandName)
        {
            case "btnLinkRankClick": Response.Redirect("~/Student/ViewPerformanceUser.aspx?UserId=" + userId.ToString());
                break;
        }  
    }
}